//http://www.leetcode.com/2011/05/longest-substring-without-repeating-characters.html
public class Solution {
    public int lengthOfLongestSubstring(String s) {
        // Start typing your Java solution below
        // DO NOT write main() function
         int n = s.length();
          int i = 0, j = 0;
          int maxLen = 0;
          int[] exist = new int[256];
          while (j < n) {
            if (exist[s.charAt(j)] == 1) {
              maxLen = Math.max(maxLen, j-i);
              while (s.charAt(i) != s.charAt(j)) {
                exist[s.charAt(i)] = 0;
                i++;
              }
              i++;
              j++;
            } else {
              exist[s.charAt(j)] = 1;
              j++;
            }
          }
          maxLen = Math.max(maxLen, n-i);
          return maxLen;
    }

}
